{{/* Hugo Blox: Accomplishments */}}
{{/* Documentation: https://hugoblox.com/blocks/ */}}
{{/* License: https://github.com/HugoBlox/hugo-blox-builder/blob/main/LICENSE.md */}}

{{/* Initialise */}}
{{ $page := .wcPage }}
{{ $block := .wcBlock }}
{{ $columns := $block.design.columns | default "1" }}

<!-- Accomplishments widget -->
<div class="col-12 {{if eq $columns "2"}}col-lg-8{{end}}">
  {{ with $block.content.text }}{{ . | emojify | $page.RenderString }}{{ end }}

  {{ if $block.content.items }}
  {{ range $idx, $key := sort $block.content.items ".date_start" "desc" }}
    <div class="card experience course">
      <div class="card-body">
        {{- $icon := .icon | default (replace (lower .organization) " " "_") }}
        {{- $svg_icon := resources.Get (printf "media/icons/brands/%s.svg" $icon) -}}
        {{- if $svg_icon }}
        <div class="d-flex align-content-start">
          <div class="mr-2 mb-2">
            {{- with .organization_url}}<a href="{{.}}" target="_blank" rel="noopener">{{end -}}
            <img src="{{ $svg_icon.RelPermalink }}" width="56" height="56" alt="{{.organization | plainify}}" loading="lazy">
            {{- with .organization_url}}</a>{{end -}}
          </div>
          <div>
        {{ end }}

            {{- with .url -}}<a href="{{.}}" target="_blank" rel="noopener">{{- end -}}
            <div class="section-subheading card-title exp-title text-muted my-0">{{.title | markdownify | emojify}}</div>
            {{- with .url -}}</a>{{- end -}}

            <div class="card-subtitle my-0 article-metadata">
              {{- with .organization_url}}<a href="{{.}}" target="_blank" rel="noopener">{{end -}}
              {{- .organization | markdownify | emojify -}}
              {{- with .organization_url}}</a>{{end -}}

              <span class="middot-divider"></span>

              {{ (time .date_start) | time.Format ($block.content.date_format | default "Jan 2006") }}
              {{ if .date_end}}
              – {{ (time .date_end) | time.Format ($block.content.date_format | default "Jan 2006") }}
              {{end}}
            </div>

        {{- if $svg_icon}}
          </div>
        </div>
        {{end}}

        {{with .description}}
          <div class="card-text">{{. | markdownify | emojify}}</div>
        {{end}}

        {{ with .certificate_url }}
          <a class="card-link" href="{{.}}" target="_blank" rel="noopener">
            {{ i18n "see_certificate" | default "See certificate" }}
          </a>
        {{ end }}
      </div>
    </div>
  {{end}}
  {{end}}
</div>
